<template>
  <ul class="list-content">
    <li
      class="list-item"
      :class="listCurrentIndex === index ? 'active' : ''"
      v-for="(item, index) in 10"
      :key="index"
      @click="changeChatList(index)"
    >
      <div class="warp">
        <div class="user-img">
          <img src="@/assets/images/user.png" alt="" />
        </div>
        <template v-if="$route.path === '/message'">
          <div class="user-info">
            <div class="nick">小天{{ item }}</div>
            <div class="time">2mins</div>
          </div>
          <div class="dots">3</div>
        </template>
        <template v-else>
          <div class="user-info2">
            <div class="nick">联系人{{ item }}</div>
          </div>
        </template>
      </div>
    </li>
  </ul>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRoute } from 'vue-router'
const $route = useRoute()

// 当前选中的聊天下标
let listCurrentIndex = ref<number>(-1);
// 点击聊天列表切换的回调
const changeChatList = (index: number) => {
  listCurrentIndex.value = index
}
</script>

<style scoped lang="scss">
.list-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  .list-item {
    width: 100%;
    height: 80px;
    display: flex;
    justify-content: center;
    .warp {
      width: 200px;
      height: 100%;
      display: flex;
      align-items: center;
      .user-img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        overflow: hidden;
        img {
          width: 40px;
          height: 40px;
        }
      }
      .user-info {
        flex: 1;
        height: 40px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding-left: 10px;
        box-sizing: border-box;
        .nick {
          font-size: 15px;
        }
        .time {
          font-size: 13px;
        }
      }
      .user-info2 {
        flex: 1;
        height: 40px;
        display: flex;
        align-items: center;
        padding-left: 10px;
        box-sizing: border-box;
      }
      .dots {
        width: 18px;
        height: 18px;
        background-color: red;
        border-radius: 50%;
        overflow: hidden;
        font-size: 12px;
        color: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }
  }
  .active {
    background-color: #f4f4f4;
  }
}
</style>
